package com.mh.common;

import com.baomidou.mybatisplus.extension.api.R;
import lombok.Data;

import javax.annotation.Resource;

/**
 * 前后端数据传输统一格式
 */
@Data
public class Result {
    private int code;//编码
    private String msg;//消息，成功还是失败
    private Long total;//总记录数
    private Object data;//数据


    public static Result fail(){
        return result(400,"失败",0L,null);
    }
    public static Result fail(String message){
        return result(400,message,0L,null);
    }
    public static Result suc(){
        return result(200,"成功",0L,null);
    }
    public static Result suc(Object data){
        return result(200,"成功",0L,data);
    }
    public static Result suc(Object data,Long total){
        return result(200,"成功",total,data);
    }


    public static Result result(int code,String msg,Long total,Object data){
        Result res=new Result();
        res.setData(data);
        res.setMsg(msg);
        res.setCode(code);
        res.setTotal(total);
        return res;
    }
}
